package com.taxigang.client.uibinder;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DecoratedPopupPanel;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextArea;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.taxigang.client.TaxiGangHandler;
import com.taxigang.shared.ContactInfo;

public class ContactForm{
	final DecoratedPopupPanel simplePopup = new DecoratedPopupPanel(true);

	public ContactForm(){
		Grid grid = new Grid(2, 2);
		
		Label nameLabel = new Label("Name:");
		final TextBox nameBox = new TextBox();
		Label emailLabel = new Label("Email:");
		final TextBox emailBox = new TextBox();
		Label messageLabel = new Label("Message:");
		final TextArea textArea = new TextArea();
		textArea.setSize("400px","200px");
		
		grid.setWidget(0, 0, nameLabel);
		grid.setWidget(0, 1, nameBox);
		grid.setWidget(1, 0, emailLabel);
		grid.setWidget(1, 1, emailBox);

		VerticalPanel vp = new VerticalPanel();
		vp.add(grid);
		vp.add(messageLabel);
		vp.add(textArea);
		
		Button send = new Button("Send");
		
		vp.add(send);
		
		send.addClickHandler(new ClickHandler() {
			
			@Override
			public void onClick(ClickEvent event) {
				ContactInfo info = new ContactInfo();
				info.setName(nameBox.getText());
				info.setEmail(emailBox.getText());
				info.setMessage(textArea.getText());
				TaxiGangHandler.getInstance().sendContactInfo(info);
				simplePopup.hide();

			}
		});
		
		simplePopup.setWidget(vp);

	}
	
	public void show(){
		simplePopup.show();
	}

	public void setPopupPosition(int left, int top) {
		simplePopup.setPopupPosition(left, top);
		
	}

}
